Skip to content

Improve CLI error handling#179

Open
atomer-nvidia wants to merge 3 commits into
nvidia-riva:mainfrom
atomer-nvidia:main
Open

Improve CLI error handling#179
atomer-nvidia wants to merge 3 commits into
nvidia-riva:mainfrom
atomer-nvidia:main

Conversation

@atomer-nvidia
Copy link
Copy Markdown
Contributor

No description provided.

atomer-nvidia and others added 3 commits May 14, 2026 11:11
Defer the pyaudio import to the points where it is actually needed
(MicrophoneStream.__enter__, SoundCallBack.__init__, list_*_devices,
get_*_info). Default WAV-output flows now work on machines without
PortAudio headers installed. When pyaudio is missing, raise an
ImportError that explicitly tells the user to install portaudio19-dev
first, addressing the VDR finding that fresh-box users got blocked by
a bare ModuleNotFoundError with no install instructions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The riva-asr/nmt/tts client scripts historically exit 0 on most error
paths — including "Unavailable model", connection refused, empty/invalid
input, and missing files — which causes CI pipelines composing these
scripts via && chains to silently swallow real failures.

Add a cli_main decorator that translates uncaught exceptions into a
small, consistent set of exit codes:

  2 = bad input (missing/empty file, ValueError, IsADirectoryError)
  3 = gRPC UNAVAILABLE (server down, wrong port, network)
  4 = gRPC INVALID_ARGUMENT / NOT_FOUND (bad model/lang/voice)
  1 = anything else
  130 = SIGINT

The decorator also writes the error to stderr so CI logs surface the
cause rather than the script swallowing it. Follow-up commit wires
this into each client script.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ation

Address the VDR 26.02 finding that python-clients CLIs exit 0 on most
error paths across all three modalities. Each script now:

  - Wraps main() with @cli_main so gRPC and OS errors propagate to a
    real exit code instead of being printed and swallowed.
  - Calls sys.exit(main()) so the chosen exit code reaches the shell.

Script-specific fixes:

  scripts/nmt/nmt.py
    - Drop the inner request() try/except that swallowed every gRPC
      status; let cli_main translate it. Empty/whitespace --text and
      missing --text-file now return EXIT_BAD_INPUT (was: silent
      exit 0). Document --max-len-variation as decoder-token units
      with valid range [0, 256], default 20, and Arabic chunking note.

  scripts/tts/talk.py
    - Reject whitespace-only --text up front (defense-in-depth pair to
      the server-side fix in riva-speech that closed the hang on
      `--text "   "`). Drop the broad `except Exception` that
      stringified gRPC errors and exited 0.

  scripts/asr/transcribe_file*.py
    - Replace `print(...); return` on missing input files with
      EXIT_BAD_INPUT. Remove the silent grpc.RpcError swallow in
      transcribe_file_offline.py.

  scripts/asr/transcribe_mic.py + realtime_asr_client.py + tts/talk.py
    - Pyaudio install hint now mentions `apt-get install -y
      portaudio19-dev` (Debian/Ubuntu) and `brew install portaudio`
      (macOS), pairing with the prereqs doc landed in documentation_2.

  scripts/tts/realtime_tts_client.py
    - Drop the module-level `from riva.client.audio_io import
      SoundCallBack` import (it was unused and pulled pyaudio in
      eagerly, defeating the lazy import). Drop the broad
      `except Exception` that mapped every failure to exit 1.

  scripts/nmt/nmt_speech_to_{text,speech}.py
    - Drop unused `import grpc`; remove the catch-all that printed
      "Error during translation" and exited 0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant